<template>
  <j-modal
    title="处置"
    :width="600"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-form-model ref="form" :rules="rules" :model="model">
      <a-form-model-item label="处置内容" v-bind="formItemLayout" prop="disposalContents">
        <a-textarea v-model="model.disposalContents" placeholder="请输入至少五个字符" :auto-size="{ minRows: 5, maxRows: 8 }" />
      </a-form-model-item>
    </a-form-model>
  </j-modal>
</template>
<script>
import * as specialApi from '@/api/xlgc/special.js'
export default {
  data () {
    return {
      visible: false,
      status: null,
      model: {},
      formItemLayout: {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 4 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 18 }
        }
      },
      rules: {
        disposalContents: [
          { required: true, message: '请输入处置内容' },
          { min: 5, message: '请输入至少五个字符', trigger: 'change' }
        ]
      }
    }
  },
  methods: {
    show(status, record) {
      if (status == 'addDispose') {
        this.$set(this.model, 'specialPersonnelId', record.specialId)
      } else if (status == 'editDispose') {
        this.$set(this.model, 'specialPersonnelId', record.specialId)
        this.$set(this.model, 'disposeId', record.disposeId)
        this.$set(this.model, 'disposalContents', record.disposalContents)
      } else if (status == 'alarmDispose') {
        this.$set(this.model, 'alarmInfoId', record.alarmInfoId)
        this.$set(this.model, 'disposalContents', record.disposalContents)
      }
      this.status = status
      this.visible = true
    },
    handleOk() {
      let api
      this.$refs.form.validate(valid => {
        if (valid) {
          if (this.status == 'addDispose') {
            api = specialApi.addDisposal(this.model)
          } else if (this.status == 'editDispose') {
            api = specialApi.updateDisposal(this.model)
          } else if (this.status == 'alarmDispose') {
            api = specialApi.fillInAlarm(this.model)
          }
          api.then(res => {
            if (res.success) {
              this.$message.success(res.message)
              this.handleCancel()
              this.$emit('ok', this.status)
            } else {
              this.$message.warn(res.message)
            }
          }).catch(e => {
            this.$message.warn('操作失败！')
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleCancel() {
      this.model = {}
      this.visible = false
    }
  }
}
</script>
<style lang="less" scoped>
</style>
